<?php
$title = (set_value('title') == '')?$acomdationdetails['title']:set_value('title');
$desc = (set_value('desc') == '')?$acomdationdetails['desc']:set_value('desc');
$date_from = (set_value('date_from') == '')?$acomdationdetails['date_from']:set_value('date_from');
$date_to = (set_value('date_to') == '')?$acomdationdetails['date_to']:set_value('date_to');
$isactive = (set_value('isactive') == '')?$acomdationdetails['isactive']:set_value('isactive');
//$image = (set_value('image') == '')?$acomdationdetails['image']:set_value('image');
$id = ($this->input->post('id') == '')?$acomdationdetails['id']:$this->input->post('id');
$action=(($acomdationdetails['id'] || $this->input->post('id')!='')?"doeditfeaturedacomdation":"doaddfeaturedaccomodation");
?>
<div class="form_content">
    <header><h3>Post New Featured Accommodation</h3></header>
    <div class="module_content">
        <?php if($image_deleted):?>
        <div class="error"><?php echo $image_deleted; ?></div>
        <?php endif;?>
        <form name="featuredaccform" id="featuredaccform"  action="<?php echo base_url(); ?>secu/accomodation/<?php echo $action;?>" method="post" onsubmit="return validateForm()">
            <input type="hidden" name="id" id="id" value="<?php echo $id; ?>">
        <fieldset style="width:40%;">
            <label>Title</label>
            <input type="text" name="title" id="title" value="<?php echo $title; ?>" style="width:92%;">
             <?php echo form_error('title'); ?>
        </fieldset>
        <fieldset style="width:40%;">
            <label>Description</label>
            <textarea name="desc" id="desc" rows="2" cols="15"><?php echo $desc; ?></textarea>
             <?php echo form_error('desc'); ?>
        </fieldset>
        <fieldset style="width:40%;">
            <label>Date from</label>
            <input type="text" name="date_from" id="date_from" value="<?php echo $date_from; ?>" style="width:92%;">
             <?php echo form_error('date_from'); ?>
        </fieldset>
        <fieldset style="width:40%;">
            <label>Date to</label>
            <input type="text" name="date_to" id="date_to" value="<?php echo $date_to; ?>" style="width:92%;">
             <?php echo form_error('date_to'); ?>
        </fieldset>
        <fieldset style="width:40%;">
            <label style="width: 10%;">Status</label>
            <input <?php echo ($isactive==1)?"checked":""; ?> type="checkbox" name="isactive" value="1" style="width:20%;">
             <?php echo form_error('isactive'); ?>
        </fieldset>
         
          <fieldset style="width:38%;padding: 1%;">

            <input type="submit" name="submit" id="submit" value="SAVE" >&nbsp;
            <input type="reset" name="reset" id="reset" value="RESET" >
        </fieldset>
<div class="clear"></div>
</form>
<?php if ($id!=''):?>
<div class="clear"></div>
<form enctype="multipart/form-data" id="fupload" method="post" action="<?php echo base_url(); ?>secu/accomodation/savefeaturedaccimages/featuredacc">
    <input type="hidden" name="id" value="<?php echo $id;?> " id="id">
    <input type="hidden" name="upload_from" value="featuredacc" id="upload_from">
    <a name="img"></a>
    <fieldset style="width:50%; float:left; padding: 10px 0 10px 10px;">
    <input name="userfile" type="file" size="40"/>
    <input type="submit" name="btn_upload" value="Upload &uarr;" class="btnupload"/>
    </fieldset>
    <?php if (isset ($imgerror)) { ?>
    <div class="error"><?php echo $imgerror; ?></div>
    <?php } ?>

</form>
<div class="clear"></div>
<fieldset style="padding: 10px; width:200px">
 <?php if($acomdationdetails['image']) { ?>

            <div class="imgbox">
                <a class=""  href="<?php echo base_url(); ?>images/uploads/original/<?php echo $acomdationdetails['image'] ?>">
                <img class="thumb" name="thumb" id="" src="<?php echo base_url(); ?>images/uploads/thumb/thumb_<?php echo $acomdationdetails['image'] ?>"/>
                </a>
                <div>
                    <a class="adel" href="<?php echo base_url()?>secu/accomodation/deletefeaturedaccimage/name/<?php echo $acomdationdetails['image']; ?>/id/<?php echo $acomdationdetails["id"] ;?>">
                    <img src="<?php echo base_url(); ?>images/admin/icn_trash.png" title="Trash">delete
                    </a>
                </div>
            </div>

        <?php } ?>
    </fieldset>
        <div class="clear"></div>
<?php endif; ?>
</div>



</div>



<script>
$(function() {
        $( "#date_from" ).datepicker({dateFormat: "yy-mm-dd"});
        $( "#date_to" ).datepicker({dateFormat: "yy-mm-dd"});
});

 function validateForm()
 {
    var title=document.forms["featuredaccform"]["title"].value;
    var desc=document.forms["featuredaccform"]["desc"].value;
    var date_from=document.forms["featuredaccform"]["date_from"].value;     


    if (title==null || title=="")
        {
            alert("Please Enter the Title");
            document.getElementById("title").focus();
            return false;
        }
    if(desc==null || desc=="")
            {
            alert("Please Enter the Description");
            document.getElementById("desc").focus();
            return false;
        }      
    if(date_from==null || date_from=="" || !isaDate(date_from))
            {
            alert(" Please enter a valid date");
            document.getElementById("date_from").focus();
            return false;
        } 
}

function isaDate(sDate) {
    var scratch = new Date(sDate);     
    if (scratch.toString() == "NaN" || scratch.toString() == "Invalid Date") {          
        return false;
    } else {        
        return true;
    }
}
</script>

